<?php
/**
 * Created by PhpStorm.
 * User: andrew郑
 * Date: 2017/10/13
 * Time: 9:22
 */

namespace app\index\controller;


class HttpService
{
    public static function send($url,$void,$extend = null)
    {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        foreach ($void as $option => $value){
            curl_setopt($ch, $option, $value);
        }
        $result = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $curlErrNo = curl_errno($ch);
        $curlErr = curl_error($ch);
        curl_close($ch);
        if ($httpCode == "0") {
            // Time out
            throw new \Exception("Curl error number:" . $curlErr . " , Curl error details:" . $curlErr . "\r\n");
        } else if ($httpCode >= "400") {
            // We did send the notifition out and got a non-200 response
            throw new \Exception("Http code:" . $httpCode . " details:" . $result . "\r\n");
        } else {
            return $result;
        }
    }

}